package com.winning.cjfw.service.controller;

import com.winning.cjfw.service.service.IJdbcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * Created by 何强
 * date 2019/5/15
 * description
 */
@RestController
@Slf4j
public class JdbcController {

    @Autowired
    private IJdbcService iJdbcService;

    @ResponseBody
    @RequestMapping("/query")
    public Map map(@RequestParam String tableName) {
        HashMap hashMap = new LinkedHashMap();
        try {
            List<Map<String, Object>> list = iJdbcService.getPageList(tableName, 1, 10);
            hashMap.put("code", 200);
            hashMap.put("rows", list.size());
            hashMap.put(tableName, list);
        } catch (DataAccessException e) {
            log.error("查询表:{}失败，失败原因{}", tableName, e);
            hashMap.put("code", 500);
            hashMap.put("rows", null);
            hashMap.put(tableName, new ArrayList<>());
        } finally {

        }
        return hashMap;
    }
}
